package config

import "github.com/spf13/viper"

type Config struct {
	Ip             string `yaml:"ip" mapstructure:"ip"`
	Port           int    `yaml:"port" mapstructure:"port"`
	Env            string `yaml:"env" mapstructure:"env"`
	RateLimiter    bool   `yaml:"rate_limiter" mapstructure:"rate_limiter"`       // 限流器是否开启
	CircuitBreaker bool   `yaml:"circuit_breaker" mapstructure:"circuit_breaker"` // 熔断器是否开启
	Log            Log    `yaml:"log" mapstructure:"log"`
}

type Log struct {
	Level     string `yaml:"level" mapstructure:"level"`
	WriteType int    `yaml:"write_type" mapstructure:"write_type"`
	LogPath   string `yaml:"log_path" mapstructure:"log_path"`
	Rotate    string `yaml:"rotate" mapstructure:"rotate"` // 日志分割配置 y 年 M 月 d 日 h 时 m 分 s 秒
}

var Cfg Config

func ReadConfig(path string) {
	viper.SetConfigType("yaml")
	viper.SetConfigFile(path)
	if err := viper.ReadInConfig(); err != nil {
		panic(err.Error())
	}

	if err := viper.Unmarshal(&Cfg); err != nil {
		panic(err.Error())
	}
}
